void RegisterDataSetFromAliEn(TString proof="proof@alice-caf.cern.ch", TString dirFind = "/alice/sim/LHC10a18/140010/", TString file="root_archive.zip",TString anchor="AliESDs.root", TString defaultTree="esdTree", Int_t nfiles=-1) {

// if (nFiles > 0) ;

 /* TProof::Open(proof.Data(),"masteronly");

  if (!gProof) {
    Error("",Form("Error connecting to %s !!!!!",proof.Data()));
  }
  
  TGrid::Connect("alien://");

  if (!gGrid) {
    Error("",Form("Error connecting to AliEn !!!!!"));
  }
 */ 
  CreateDataSetFromAliEn(dirFind,file,anchor,defaultTree,proof);
  
  
}

Int_t CreateDataSetFromAliEn(TString aliendirs="/alice/sim/LHC09d10/104871", TString zipfile="root_archive.zip", TString anchor="AliESDs.root",TString defaultTree="esdTree",TString proof="aliceskaf@prf001-iep-grid.saske.sk") {

  TString whatToRemove("/alice/sim");
  
  TString datasetname=aliendirs;
  datasetname.ReplaceAll(Form("%s/",whatToRemove.Data()),"");
  datasetname.ReplaceAll("/","_");
  // remove last _
  
  
  Bool_t forceOverWriteDataset=kFALSE;
  Bool_t trustInfo=kFALSE;
  
  Int_t ret = 0;
//   gSystem->Exec(Form("rm /tmp/%s.txt &> /dev/null", datasetname.Data()));
//   TString myTmpFileName = Form("/tmp/%s.txt", datasetname.Data());
  if (aliendirs.IsNull()) return 1;
  
    // chcek for alien
    TGrid::Connect("alien://");
    if (!gGrid) {
      Error("","Error connecting to AliEn !!!");
      return 1;
    }
    gGrid->Command(Form("rm %s/%s","/alice/cern.ch/user/m/mvala/",datasetname.Data()));

//     ofstream tmpFileList(myTmpFileName.Data());
//     if (!tmpFileList) {
//       Error("StageFromAliEnToProof", Form("Cannot open file %s", myTmpFileName.Data()));
//       return 2;
//     }
    Info("",aliendirs.Data());
    TAlienResult* gr;
//     TObjArray* array = aliendirs.Tokenize(",");
//     TObjString *str;
//     TString strr,tmpfilename,tmpfileline;
    gr = (TAlienResult*) gGrid->Command(Form("find -c %s %s/* %s",datasetname.Data(),aliendirs.Data(),zipfile.Data()));
  
//   tmpFileList.close();
//  return 0;

  TAlienCollection *gridColl = gGrid->OpenCollection(Form("alien:///alice/cern.ch/user/m/mvala/%s",datasetname.Data()));
  TFileCollection *proofColl = gridColl->GetFileCollection(); 
  if (!anchor.IsNull())
    proofColl->SetAnchor(anchor.Data());
  
//   // connect to proof cluster
  TProof::Open(proof.Data(),"masteronly");
  if (!gProof) {
    Error("",Form("Error connecting to %s !!!!!",proof.Data()));
    return 3;
  }
  
  if (forceOverWriteDataset) gProof->RemoveDataSet(datasetname.Data());
  
  TString extraParameters;
  if (forceOverWriteDataset) extraParameters+="O";
  if (trustInfo) extraParameters+="T";
  
  Info("CreateDataSetFromAliEn",Form("Dataset %s registred with options : %s",datasetname.Data(),extraParameters.Data()));
  gProof->RegisterDataSet(datasetname.Data(),proofColl,extraParameters.Data());

  if (!defaultTree.IsNull())
    gProof->SetDataSetTreeName(datasetname.Data(),defaultTree.Data());
  
  gProof->ShowDataSets();
//   gGrid->Command(Form("rm -f /alice/cern.ch/user/p/proof/datasets/%s/%s.root",whatToRemove.Data(),datasetname.Data()));
//   TFile::Cp(Form("/pool/PROOF-AAF/proof/pool/dataset/default/proof/%s.root",datasetname.Data()),Form("alien:///alice/cern.ch/user/p/proof/datasets/%s/%s.root",whatToRemove.Data(),datasetname.Data()));
  
//   gProof->RemoveDataSet(datasetname.Data());
  
//   gProof->ShowDataSets();
//   gSystem->Rm(Form("tmp_%s.txt", datasetname.Data()));
  
  return 0;
}
